﻿var openNormalPage = function (url, target, width, height) {
    if (typeof (width) == "undefined" || width.length == 0 || width == 0) {
        width = 850;
    }
    if (typeof (height) == "undefined" || height.length == 0 || height == 0) {
        height = 750;
    }
    var features = "height=" + height + ",width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no,autosize=true;";
    window.open(url, target, features, true);
}
var openModalPage = function (url, width, height, args) {
    if (typeof (width) == "undefined" || width.length == 0 || width == 0) {
        width = 850;
    }
    if (typeof (height) == "undefined" || height.length == 0 || height == 0) {
        height = 750;
    }
    var features = "dialogWidth=" + width + "px;dialogHeight=" + height + "px;toolbar=no;locationbar=no;scroll=yes;resizable =yes";
    window.showModalDialog(url, args, features);
}
//编辑页面
var Edit = function (url, width, height, features) {
    var win = openModalPage(url, width, height, features);
    window.document.forms[0].submit();
}
///删除数据
var Delete = function (url) {
    if (confirm("确定要删除吗？")) {
        $.post(url, null, function (d) {
            if (d > 0) {
                alert("删除成功!");
                window.document.forms[0].submit();
            } else {
                alert("删除失败!");
            }
        });
    }
}
//加载图片
var LoadImgs = function (ResourceID, imgcontainerID, imgclass) {
    if (typeof (imgclass) == "undefined" || imgclass.length == 0) imgclass = "img-thumbnail";
    $.get('/Admin/File/GetFiles/?ResourceID=' + ResourceID, function (d) {
        if (typeof (d) != "undefined" && d.length > 0) {
            $("#" + imgcontainerID).html("");
            for (var i = 0; i < d.length; i++) {
                //if (i == 0) {
                //    $("#" + imgcontainerID).append("<div class='item active'><img src='/images/" + d[i] + "' alt='First slide'></div>");
                //} else {
                //    $("#" + imgcontainerID).append("<div class='item'><img src='/images/" + d[i] + "' alt='First slide'></div>");
                //}
                $("#" + imgcontainerID).append("<a href='/images/"+d[i]+"' target='_blank'><img src='/Images/_thumbs/" + d[i] + "' width='50' height='60'  class='" + imgclass + " bigimgs' bigimg='/Images/" + d[i] + "'/></a>");
            }
        }
    });
}

$(function () {



    //关闭页面
    $("#btnClose").click(function () { window.close(); });
    $("#btnReset").click(function () { $("input[type=text]").val(""); $("select").val(""); $("#btnSearch").click(); });
    $("#btnSubmit").click(function () {
        if ($(this).closest("form").valid()) {
            $(this).closest("form").submit();
            window.top.close();
        }
    });

    //附件
    $("#btnUpload").click(function () {
        $('#AttachUrl').uploadify("upload");
    })
    
    //$("#imgpreview").delegate(".bigimgs", "click", function () {
    //    $("img").attr("src", $(this).attr("bigimg")).show("slow");
    //});
})